home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 298_01 / curses.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-07-23  |  15.3 KB  |  456 lines

  1. /* PC Curses. (C) Copyright 1987 Jeffrey S. Dean.  All Rights Reserved. */
  2.  
  3. /* curses.h -- include file for PC Curses */
  4.  
  5. #ifndef PC_CURSES
  6.  
  7. /* PC_CURSES is used to identify this particular package;
  8.  *  also ensures that this file is processed only once.
  9.  */
  10. #define PC_CURSES
  11.  
  12. #include <stdio.h>
  13.  
  14. /* version information */
  15. extern char *_pc_curses;
  16.  
  17. /* characters in PC Curses are always of type CHTYPE
  18.  *  in the current implementation, the upper byte is
  19.  *  used to store attribute information.
  20.  */
  21. #define CHTYPE short
  22.  
  23. /* the basic window structure */
  24. typedef struct  _win {
  25.     CHTYPE **txt;            /* text, as an array of line ptrs */
  26.     short cury, curx;        /* current x and y coordinates */
  27.     short ox, oy;            /* x and y origin */
  28.     short lines, cols;        /* size of full screen */
  29.     short mfy, mfx, mly, mlx;    /* area to be refreshed */
  30.     CHTYPE attrs;            /* screen attributes */
  31.     short flags;            /* miscellaneous information */
  32.     short scrtop, scrbot;        /* scrolling region boundaries */
  33.     CHTYPE *base;            /* base address of character map */
  34. } WINDOW;
  35.  
  36. #define A_ATTRIBUTES    0xff00
  37. #define A_CHARTEXT    0x00ff
  38.  
  39. /* Support is provided for both monochrome and color displays,
  40.  *  by providing a set of attributes that can be used with
  41.  *  the "attr" functions.
  42.  *
  43.  *  The meaning of the attributes depends on the display used.
  44.  *  Note that the meanings may not translate well: for example,
  45.  *  "underline" on a color display appears as blue text on a 
  46.  *  black background.
  47.  */ 
  48.  
  49. /* Although an attrbiute of zero means "invisible" on a PC, this package
  50.  * has been hacked (for compatibility) so that zero also means "normal".
  51.  */
  52. #define    A_NONE        0
  53. #define A_NORMAL    0x0700
  54.  
  55. /* On a PC, if !(attributes & A_VISIBLE), character will be invisible */
  56. #define A_VISIBLE    0x7700
  57.  
  58. /* screen attributes for (monochrome) IBM PC
  59.  *   Note that not all combinations are meaningful;
  60.  *   see a PC reference manual for more info.
  61.  */
  62. #define A_REVERSE    0x7000 
  63. #define A_UNDERLINE    0x0100 
  64. #define A_BOLD        0x0800 
  65. #define A_BLINK        0x8000 
  66. #define A_STANDOUT    A_REVERSE 
  67. #define A_DIM        A_NONE
  68.  
  69. /* color attributes
  70.  *  use the A_COLOR macro to specify foreground and background colors.
  71.  *  For example, to set the stdscr to use green characters on a yellow
  72.  *  background, you would say:
  73.  *    attrset( A_COLOR(A_GREEN, A_YELLOW) );
  74.  */
  75. #define A_COLOR(fore,back)    ( (fore) << 8 | (back) <<12 )
  76.  
  77. /* primary colors */
  78. #define A_BLACK        0
  79. #define A_BLUE        1
  80. #define A_GREEN        2
  81. #define A_RED        4
  82.  
  83. /* secondary colors (combinations of primary colors) */
  84. #define A_CYAN        3    /* blue-green */
  85. #define A_MAGENTA    5    /* purple */
  86. #define A_BROWN        6    /* (or dark yellow) */
  87. #define A_WHITE        7    /* white (or light gray) */
  88.  
  89. /* the "intensity" bit
  90.  *  Warning: If used on the background color, the intensity bit
  91.  *  will cause the text to blink.  This reduces the number of
  92.  *  background colors from 16 to 8.  (There is a hardware-dependent
  93.  *  method around this problem, but PC Curses does not support it.)
  94.  */
  95. #define A_INTENSE    8
  96.  
  97. /* "light" colors */
  98. #define A_GRAY        (A_INTENSE|A_BLACK)
  99. #define A_LBLUE        (A_INTENSE|A_BLUE)
  100. #define A_LGREEN    (A_INTENSE|A_GREEN)
  101. #define A_LCYAN        (A_INTENSE|A_CYAN)
  102. #define A_LRED        (A_INTENSE|A_RED)
  103. #define A_LMAGENTA    (A_INTENSE|A_MAGENTA)
  104. #define A_YELLOW    (A_INTENSE|A_BROWN)
  105. #define A_BRIGHTWHITE    (A_INTENSE|A_WHITE)
  106.  
  107. /* Unix Sys V.3 extended character set
  108.  *
  109.  * Note: this is an approximation of the V.3 approach,
  110.  * which requires that all line graphics characters have the
  111.  * bit A_ALTCHARSET turned on (if it is off, it means that
  112.  * the terminal does not support that particular character).
  113.  * Since PC Curses provides color support (see above), there are
  114.  * no extra bits available for A_ALTCHARSET.  As an approximation,
  115.  * A_ALTCHARSET is defined as 0x80.  Since many of the PC graphics
  116.  * characters have this bit set, this approximation works most of
  117.  * the time.  However, some graphics characters fall in the range
  118.  * 0x00 to 0x1F, which means that testing for A_ALTCHARSET will
  119.  * fail.
  120.  */
  121. #define A_ALTCHARSET    0x0080
  122. #define ACS_ULCORNER    218
  123. #define ACS_LLCORNER    192
  124. #define ACS_URCORNER    191
  125. #define ACS_LRCORNER    217
  126. #define ACS_RTEE    180
  127. #define ACS_LTEE    195
  128. #define ACS_BTEE    193
  129. #define ACS_TTEE    194
  130. #define ACS_HLINE    196
  131. #define ACS_VLINE    179
  132. #define ACS_PLUS    '+'
  133. #define ACS_DIAMOND    4
  134. #define ACS_CKBOARD    176
  135. #define ACS_DEGREE    248
  136. #define ACS_PLMINUS    241
  137. #define ACS_BULLET    249
  138. #define ACS_LARROW    27
  139. #define ACS_RARROW    26
  140. #define ACS_DARROW    25
  141. #define ACS_UARROW    24
  142. #define ACS_BOARD    '#'
  143. #define ACS_LANTERN    '#'
  144.  
  145. /* "double line" characters (not defined by SysV.3) */
  146. #define ACS_DULCORNER    201
  147. #define ACS_DLLCORNER    100
  148. #define ACS_DURCORNER    187
  149. #define ACS_DLRCORNER    188
  150. #define ACS_DRTEE    185
  151. #define ACS_DLTEE    204
  152. #define ACS_DBTEE    202
  153. #define ACS_DTTEE    203
  154. #define ACS_DHLINE    205
  155. #define ACS_DVLINE    186
  156.  
  157. /* Curses provides getyx() to return current coordinates; newer versions
  158.  * of curses also provide getbegyx() and getmaxyx() to return beginning
  159.  * and ending coordinates.  The coordinate accessing macros below are
  160.  * non-standard, but they allow just a single coordinate to be accessed.
  161.  * This saves the trouble of declaring an unneeded variable, eliminates
  162.  * an unneeded assignment, and prevents the compiler (or lint) from
  163.  * complaining about a variable that is set but never used.
  164.  */
  165. #define BEGY(w)        w->oy        /* starting position of window */
  166. #define BEGX(w)        w->ox
  167. #define CURY(w)        w->cury        /* current position in window */
  168. #define CURX(w)        w->curx
  169. #define MAXY(w)     w->lines    /* number of lines */
  170. #define MAXX(w)        w->cols        /* number of columns */
  171. #define WGETC(w,y,x)    w->txt[y][x]    /* get character from window */
  172. #define WPUTC(w,y,x,c)    w->txt[y][x]=c    /* place character in window */
  173.  
  174. /* for win->flags */
  175. /* #define W_WRAPOK    0x1        /* ok for lines to wrap around */
  176. #define W_CLEAROK    0x2        /* ok to clear window */
  177. #define W_MODIFIED    0x4        /* window has been modified */
  178. #define W_SCROLLOK    0x8        /* ok to scroll window */
  179. #define W_KEYPAD    0x10        /* use keypad translations */
  180. #define W_NODELAY    0x20        /* non-blocking tty input */
  181. #define W_TOUCHED    0x40        /* window has been touched */
  182. #define W_SUBWIN    0x80        /* window is a sub-window */
  183. #define W_LEAVEOK    0x100        /* ignore cursor */
  184. #define W_META        0x200        /* enable meta mode */
  185. #define W_PAD        0x400        /* window is really a pad */
  186. #define W_PADNOCUR    0x800        /* internal pad cursor control */
  187. #define W_FULLWIN    0x1000        /* window is full screen */
  188.  
  189. /* macros to set/clear win->flags */
  190. #define scrollok(win,flag)    _winflag(win,flag,W_SCROLLOK)
  191. #define nodelay(win,flag)    _winflag(win,flag,W_NODELAY)
  192. #define leaveok(win,flag)    _winflag(win,flag,W_LEAVEOK)
  193. #ifndef SIMPGETCH
  194. #define keypad(win,flag)    _winflag(win,flag,W_KEYPAD)
  195. #define meta(win,flag)        _winflag(win,flag,W_META)
  196. #endif
  197. #define clearok(win,flag) \
  198.     ( (win)->flags & W_FULLWIN ? _winflag(win, flag, W_CLEAROK) : ERR )
  199.  
  200. /* standard stuff for curses */
  201. #define TRUE    1
  202. #define FALSE    0
  203. #define    ERR    0
  204. #define    OK    1
  205.  
  206. /* standard curses variables */
  207. extern int LINES, COLS;            /* size of full screen */
  208. extern WINDOW *stdscr, *curscr;        /* current and standard screens */
  209.  
  210. /* for tty input emulation mode */
  211. extern int _ttyflags;
  212.  
  213. #define T_RAW    01
  214. #define T_CRMOD    02
  215. #define T_ECHO    04
  216. #define T_NONL    010
  217.  
  218. /* settings for screen update method; this is still experimental */
  219. #define T_BIOS        0        /* use bios updating */
  220. #define T_DIRECT    -1        /* direct update, figure out type */
  221. #define T_MA        0xb000        /* direct update, assume monochrome */
  222. #define T_CGA        0xb800        /* direct update, assume cga */
  223. #define T_EGA        0xa800        /* direct update, assume ega ?? */
  224.  
  225. /* PC line drawing characters (horizontal/vertical pairs) */
  226. #define S_HOR    196    /* single line */
  227. #define S_VERT    179
  228. #define D_HOR    205    /* double line */
  229. #define D_VERT    186
  230. #define T_HOR    220    /* thick solid line, not quite perfect */
  231. #define T_VERT    219
  232.  
  233. WINDOW    *initscr(), *newwin(), *subwin(), *newpad();
  234. WINDOW    *shadowwin();
  235. char    *unctrl();
  236.  
  237. #define    getyx(win,y,x)        (y = CURY(win), x = CURX(win))
  238. #define getbegyx(win,y,x)    (y = BEGY(win), x = BEGX(win))
  239. #define getmaxyx(win,y,x)    (y = MAXY(win), x = MAXX(win))
  240.  
  241. #define raw()            _ttyflags |= T_RAW
  242. #define noraw()            _ttyflags &= ~T_RAW
  243. #define crmode()        _ttyflags |= T_CRMOD
  244. #define nocrmode()        _ttyflags &= ~T_CRMOD
  245. /* cbreak and crmode refer to the same thing */
  246. #define cbreak()        _ttyflags |= T_CRMOD
  247. #define nocbreak()        _ttyflags &= ~T_CRMOD
  248. #define echo()            _ttyflags |= T_ECHO
  249. #define noecho()        _ttyflags &= ~T_ECHO
  250. #define nonl()            _ttyflags |= T_NONL
  251. #define nl()            _ttyflags &= ~T_NONL
  252.  
  253. #define savetty()
  254. #define resetty()
  255. #define gettmode()
  256. #define setterm(x)
  257.  
  258. #define    getch()        wgetch(stdscr)
  259. #define    addch(ch)    waddch(stdscr, ch)
  260. #define    addstr(str)    waddstr(stdscr, str)
  261. #define    move(y, x)    wmove(stdscr, y, x)
  262. #define    clear()        wclear(stdscr)
  263. #define    erase()        werase(stdscr)
  264. #define    clrtobot()    wclrtobot(stdscr)
  265. #define    clrtoeol()    wclrtoeol(stdscr)
  266. #define getstr(buf)    wgetstr(stdscr,buf)
  267. #define    insertln()    winsertln(stdscr)
  268. #define    deleteln()    wdeleteln(stdscr)
  269. #define    refresh()    wrefresh(stdscr)
  270. #define    inch()        winch(stdscr)
  271. #define    insch(c)    winsch(stdscr,c)
  272. #define    delch()        wdelch(stdscr)
  273. #define    standout()    wstandout(stdscr)
  274. #define    standend()    wstandend(stdscr)
  275. #define    attron(at)    wattron(stdscr,at)
  276. #define    attroff(at)    wattroff(stdscr,at)
  277. #define    attrset(at)    wattrset(stdscr,at)
  278. #define setscrreg(t,b)    wsetscrreg(stdscr,t,b)
  279.  
  280. #ifdef SIMPMOVE
  281. /* SIMPMOVE provides a simplified version of wmove()
  282.  *  by circumventing error checking.  Its use is not
  283.  *  recommended unless legal values can be guaranteed.
  284.  *  It is normally undefined.
  285.  */
  286. #define wmove(win,y,x)        ((win)->cury=(y),(win)->curx=(x),OK)
  287. #endif
  288.  
  289. #define    mvwaddch(win,y,x,ch)    (wmove(win,y,x)==ERR ? ERR: waddch(win,ch))
  290. #define    mvwgetch(win,y,x)    (wmove(win,y,x)==ERR ? ERR: wgetch(win))
  291. #define    mvwaddstr(win,y,x,str)    (wmove(win,y,x)==ERR ? ERR: waddstr(win,str))
  292. #define    mvwgetstr(win,y,x,str)    (wmove(win,y,x)==ERR ? ERR: wgetstr(win,str))
  293. #define    mvwinch(win,y,x)    (wmove(win,y,x)==ERR ? ERR: winch(win))
  294. #define    mvwdelch(win,y,x)    (wmove(win,y,x)==ERR ? ERR:(wdelch(win),OK))
  295. #define    mvwinsch(win,y,x,c)    (wmove(win,y,x)==ERR ? ERR:(winsch(win,c),OK))
  296. #define    mvaddch(y,x,ch)        mvwaddch(stdscr,y,x,ch)
  297. #define    mvgetch(y,x)        mvwgetch(stdscr,y,x)
  298. #define    mvaddstr(y,x,str)    mvwaddstr(stdscr,y,x,str)
  299. #define    mvgetstr(y,x,str)    mvwgetstr(stdscr,y,x,str)
  300. #define    mvinch(y,x)        mvwinch(stdscr,y,x)
  301. #define    mvdelch(y,x)        mvwdelch(stdscr,y,x)
  302. #define    mvinsch(y,x,c)        mvwinsch(stdscr,y,x,c)
  303.  
  304. /* we made these into macros */
  305. #define wstandout(win)        (win)->attrs |= A_STANDOUT
  306. #define wstandend(win)        (win)->attrs = A_NONE
  307. #define wattroff(win,at)    (win)->attrs &= ~(at)
  308. #define wattron(win,at)        (win)->attrs |= (at)
  309. #define wattrset(win,at)    (win)->attrs = (at)
  310. /* for some reason, there is no standard way to get attributes;
  311.  *  hence, wattrget...
  312.  */
  313. #define wattrget(win)        (win)->attrs
  314. #define attrget()        wattrget(stdscr)
  315.  
  316. #define winch(win)        ((win)->txt[(win)->cury][(win)->curx])
  317.  
  318. /* overlay() and overwrite() are cases of copywin() */
  319. #define overlay(src, dst) \
  320.     copywin(src, dst, 0, 0, 0, 0, \
  321.     min(MAXY(src), MAXY(dst)) - 1, min(MAXX(src), MAXX(dst)) - 1, 1)
  322. #define overwrite(src, dst) \
  323.     copywin(src, dst, 0, 0, 0, 0, \
  324.     min(MAXY(src), MAXY(dst)) - 1, min(MAXX(src), MAXX(dst)) - 1, 0)
  325.  
  326. /* PC Curses only
  327.  *    The terminfo and termcap curses definitions of winch() are different.
  328.  *    PC Curses uses the terminfo definition.  For the convenience of
  329.  *    termcap curses uses, the macro wcinch() and its variants provide
  330.  *    the old function.
  331.  */
  332. #define wcinch(win)        (A_CHARTEXT & winch(win)) 
  333. #define cinch()            wcinch(stdscr)
  334. #define    mvwcinch(win,y,x)    (wmove(win,y,x)==ERR?ERR:wcinch(win))
  335. #define    mvcinch(y,x)        mvwcinch(stdscr,y,x)
  336.  
  337. /* for compatibility -- no need for cursor optimization */
  338. #define mvcur(fy, fx, ty, tx)    _mvcur(ty, tx)
  339.  
  340. #define flushinp()         bdos(0xC,0xFF,6)
  341.  
  342. /* "funny" function definitions */
  343. #define idlok(win,flag)
  344. #define longname(tbuf,buf)    strcpy(buf, "ibm-pc")
  345. #define draino(X)        ERR
  346. #define intrflush(win,flg)
  347. #define typeahead(fd)
  348. #define baudrate()        9600    /* or any value you want! */
  349. /* erasechar and killchar are used by getstr(); you can set
  350.  * your own values if you recompile getstr() or do not use it.
  351.  */
  352. #define erasechar()    '\b'        /* backspace */
  353. #define killchar()    '\025'        /* Control-U */
  354.  
  355. /* extended key definitions */
  356. #define KEY_BREAK    0401    /* unused */
  357. #define KEY_DOWN    0402
  358. #define KEY_UP        0403
  359. #define KEY_LEFT    0404
  360. #define KEY_RIGHT    0405
  361. #define KEY_HOME    0406
  362. #define KEY_F0        0410
  363. #define KEY_F(x)    (KEY_F0+(x))
  364. #define KEY_DL        0510    /* unused */
  365. #define KEY_IL        0511    /* unused */
  366. #define KEY_DC        0512
  367. #define KEY_IC        0513
  368. #define KEY_EIC        0514    /* unused */
  369. #define KEY_CLEAR    0515    /* unused */
  370. #define KEY_EOS        0516    /* unused */
  371. #define KEY_EOL        0517    /* unused */
  372. #define KEY_SF        0520    /* unused */
  373. #define KEY_SR        0521    /* unused */
  374. #define KEY_NPAGE    0522
  375. #define KEY_PPAGE    0523
  376. #define KEY_STAB    0524    /* unused */
  377. #define KEY_CTAB    0525    /* unused */
  378. #define KEY_CATAB    0526    /* unused */
  379. #define KEY_ENTER    0527    /* unused */
  380. #define KEY_SRESET    0530    /* unused */
  381. #define KEY_RESET    0531    /* unused */
  382. #define KEY_PRINT    0532    /* unused */
  383. #define KEY_LL        0533    /* unused */
  384. #define KEY_BTAB    0541    /* back (shifted) tab */
  385. #define KEY_END        0550
  386.  
  387. /* PC Curses only
  388.  *    new code values start from 0600 (arbitrarily chosen)
  389.  */
  390. #define KEY_cNPAGE    0600    /* Ctrl-PgDn */
  391. #define KEY_cPPAGE    0601    /* Ctrl-PgUp */
  392. #define KEY_cHOME    0602    /* Ctrl-Home */
  393. #define KEY_cEND    0603    /* Ctrl-End */
  394. #define KEY_cLEFT    0604    /* Ctrl-LeftArrow */
  395. #define KEY_cRIGHT    0605    /* Ctrl-RightArrow */
  396. #define KEY_cPRTSC    0606    /* Ctrl-PrtSc */
  397.  
  398. /* PC Curses only: function keys with shift, control, and alt */
  399. #define KEY_sF(x)    (KEY_F(10)+x)
  400. #define KEY_cF(x)    (KEY_sF(10)+x)
  401. #define KEY_aF(x)    (KEY_cF(10)+x)
  402.  
  403. /** function prototypes **/
  404.  
  405. int    beep(void);
  406. int    box(WINDOW *,CHTYPE,CHTYPE);
  407. int    copywin(WINDOW *,WINDOW *,int,int,int,int,int,int,int);
  408. int    delwin(WINDOW *);
  409. int    doupdate(void);
  410. int    drawbox(WINDOW *,CHTYPE,CHTYPE,int,int,int,int);
  411. int    endwin(void);
  412. int    flash(void);
  413. WINDOW *initscr(void);
  414. int    mvprintw(int,int,char *,...);
  415. int    mvwin(WINDOW *,int,int);
  416. int    mvwprintw(WINDOW *,int,int,char *,...);
  417. int    mvscanw(int,int,char *,...);
  418. int    mvwscanw(WINDOW *,int,int,char *,...);
  419. WINDOW *newpad(int,int);
  420. WINDOW *newwin(int,int,int,int);
  421. int    pnoutrefresh(WINDOW *,int,int,int,int,int,int);
  422. int    prefresh(WINDOW *,int,int,int,int,int,int);
  423. int    printw(char *,...);
  424. int    scanw(char *,...);
  425. int    scroll(WINDOW *);
  426. WINDOW *shadowwin(WINDOW *,WINDOW *);
  427. WINDOW *subwin(WINDOW *,int,int,int,int);
  428. int    touchwin(WINDOW *);
  429. int    traceclose(void);
  430. int    tracedump(WINDOW *,int);
  431. int    traceoff(void);
  432. int    traceon(void);
  433. int    traceprint(char *,...);
  434. char   *unctrl(CHTYPE);
  435. int    waddch(WINDOW *,CHTYPE);
  436. int    waddstr(WINDOW *,char *);
  437. int    wclear(WINDOW *);
  438. int    wclrtobot(WINDOW *);
  439. int    wclrtoeol(WINDOW *);
  440. int    wdelch(WINDOW *);
  441. int    wdeleteln(WINDOW *);
  442. int    werase(WINDOW *);
  443. int    wgetch(WINDOW *);
  444. int    wgetstr(WINDOW *,char *);
  445. int    winsch(WINDOW *,CHTYPE);
  446. int    winsertln(WINDOW *);
  447. int    wmove(WINDOW *,int,int);
  448. int    wnoutrefresh(WINDOW *);
  449. int    wprintw(WINDOW *,char *,...);
  450. int    wrefresh(WINDOW *);
  451. int    wrelmove(WINDOW *,int,int);
  452. int    wscanw(WINDOW *,char *,...);
  453. int    wsetscrreg(WINDOW *,int,int);
  454.  
  455. #endif /* PC_CURSES */
  456.